#include <iostream>
using namespace std;

struct mem{
	int left,right;
	bool vis=false;
};


int main(){
	int start=0;
	int n;
	cin>>n;
	mem a[n];
	a[0].left = -1;
	a[0].right = -1;
	a[0].vis = true;
	for(int i=1;i<n;i++){
		int k,p;
		cin>>k>>p;
		k--;
		if(p == 0){
			a[i].right = k;
			a[i].left = a[k].left;
			a[k].left = i;
			if(a[i].left == -1)
				start = i;
			else{
				a[a[i].left].right = i;
			}
		}
		else{
			a[i].left = k;
			a[i].right = a[k].right;
			a[k].right = i;
			if(a[i].right != -1){
				a[a[i].right].left = i;
			}
		}
		a[i].vis = true;
	}
	
//	cout<<endl<<endl;
//	int index=start;
//	while(a[index].right != -1){
//		cout<<index+1<<" ";
//		index = a[index].right;
//	}
//	cout<<index+1;
//	cout<<endl<<endl;
	
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int x;
		cin>>x;
		x--;
		if(a[x].vis == false)
			continue;
		
		
		if(a[x].left != -1)
			a[a[x].left].right = a[x].right;
		if(a[x].right != -1)
			a[a[x].right].left = a[x].left;
		a[x].vis = false;
		
		
		if(a[a[x].right].left == -1)
			start = a[x].right;
	}
	while(a[start].right != -1){
		cout<<start+1<<" ";
		start = a[start].right;
	}
	cout<<start+1<<endl;
	return 0;
}
